package com.ewei.web.common.utils;

import java.util.Properties;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.support.PropertiesLoaderSupport;
public class ConfigFactoryBean extends PropertiesLoaderSupport implements FactoryBean<Properties>,InitializingBean{
	private boolean isSingleton = true;
	private Properties props = null;
	public void setIsSingleton(boolean isSingleton){
		this.isSingleton = isSingleton;
	}
	@Override
	public Properties getObject() throws Exception {
		if(isSingleton){// if is single model
			return props;
		}else{
			return mergeProperties();//reload from the location
		}
	}

	@Override
	public Class<?> getObjectType() {
		return Properties.class;
	}

	@Override
	public boolean isSingleton() {
		return isSingleton;
	}
	@Override
	public void afterPropertiesSet() throws Exception {
		this.props = mergeProperties();
	}
}
